package com.txunda.zhuohired.aty.user.resume;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.ants.theantsgo.gson.GsonUtil;
import com.ants.theantsgo.view.inScroll.ListViewForScrollView;
import com.bumptech.glide.Glide;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.txunda.zhuohired.R;
import com.txunda.zhuohired.adapter.user.resume.PreviewEducationAdapter;
import com.txunda.zhuohired.adapter.user.resume.PreviewJobHistoryAdapter;
import com.txunda.zhuohired.adapter.user.resume.PreviewProjectAdapter;
import com.txunda.zhuohired.adapter.user.resume.PreviewSelfAdapter;
import com.txunda.zhuohired.base.BaseAty;
import com.txunda.zhuohired.bean.common.CommonEducationListBean;
import com.txunda.zhuohired.bean.common.CommonJobListBean;
import com.txunda.zhuohired.bean.common.CommonPracticeListBean;
import com.txunda.zhuohired.bean.common.CommonSocialBean;
import com.txunda.zhuohired.bean.user.resume.PreviewBean;
import com.txunda.zhuohired.http.pst.ResumePst;
import com.txunda.zhuohired.view.ObservableScrollView;

import java.util.ArrayList;
import java.util.List;

import cn.gavinliu.android.lib.shapedimageview.ShapedImageView;

/**
 * 创建人： Txd_Cjh
 * 创建时间： 2018/3/8 10:02
 * 功能描述：简历预览
 * 联系方式：jiahuanchen@126.com
 */

public class PreviewAty extends BaseAty {
    /**
     * 标题
     */
    @ViewInject(R.id.tv_layout_blue_center)
    private TextView tv_layout_blue_center;
    /**
     * 分享
     */
    @ViewInject(R.id.iv_layout_blue_share)
    private ImageView iv_layout_blue_share;
    /**
     * ObservableScrollView
     */
    @ViewInject(R.id.obs_scroll_view)
    private ObservableScrollView obs_scroll_view;
    /**
     * 工作经历
     */
    @ViewInject(R.id.lv_preview_job_history)
    private ListViewForScrollView lv_preview_job_history;
    /**
     * 教育经历
     */
    @ViewInject(R.id.lv_preview_education)
    private ListViewForScrollView lv_preview_education;
    /**
     * 项目经验
     */
    @ViewInject(R.id.lv_preview_project)
    private ListViewForScrollView lv_preview_project;
    /**
     * 社交主页
     */
    @ViewInject(R.id.lv_preview_self)
    private ListViewForScrollView lv_preview_self;
    /**
     * 头像
     */
    @ViewInject(R.id.iv_preview_head)
    private ShapedImageView iv_preview_head;
    /**
     * 姓名
     */
    @ViewInject(R.id.tv_preview_name)
    private TextView tv_preview_name;
    /**
     * 职位
     */
    @ViewInject(R.id.tv_preview_job)
    private TextView tv_preview_job;
    /**
     * 电话
     */
    @ViewInject(R.id.tv_preview_phone)
    private TextView tv_preview_phone;
    /**
     * 工作经验
     */
    @ViewInject(R.id.tv_preview_suffer)
    private TextView tv_preview_suffer;
    /**
     * 学历
     */
    @ViewInject(R.id.tv_preview_education)
    private TextView tv_preview_education;
    /**
     * 薪资
     */
    @ViewInject(R.id.tv_preview_pay)
    private TextView tv_preview_pay;
    /**
     * 现居城市
     */
    @ViewInject(R.id.tv_preview_city)
    private TextView tv_preview_city;
    @ViewInject(R.id.ll_preview_city)
    private LinearLayout ll_preview_city;
    /**
     * 出生年月
     */
    @ViewInject(R.id.ll_preview_birthday)
    private LinearLayout ll_preview_birthday;
    @ViewInject(R.id.tv_preview_birthday)
    private TextView tv_preview_birthday;
    /**
     * 职位状态
     */
    @ViewInject(R.id.tv_preview_salary)
    private TextView tv_preview_salary;
    /**
     * 职位名称
     */
    @ViewInject(R.id.tv_preview_job_name)
    private TextView tv_preview_job_name;
    /**
     * 职位薪资
     */
    @ViewInject(R.id.tv_preview_job_pay)
    private TextView tv_preview_job_pay;
    /**
     * 期望工作地
     */
    @ViewInject(R.id.ll_preview_job_address)
    private LinearLayout ll_preview_job_address;
    @ViewInject(R.id.tv_preview_job_city)
    private TextView tv_preview_job_city;
    /**
     * 期望行业
     */
    @ViewInject(R.id.ll_preview_job_trade)
    private LinearLayout ll_preview_job_trade;
    @ViewInject(R.id.tv_preview_job_trade)
    private TextView tv_preview_job_trade;
    /**
     * 自我评价
     */
    @ViewInject(R.id.tv_preview_appraise)
    private TextView tv_preview_appraise;

    private PreviewJobHistoryAdapter previewJobHistoryAdapter;
    private PreviewEducationAdapter previewEducationAdapter;
    private PreviewProjectAdapter previewProjectAdapter;
    private PreviewSelfAdapter previewSelfAdapter;

    private List<CommonPracticeListBean> jobList;//工作经历
    private List<CommonEducationListBean> educationList;//教育经历
    private List<CommonJobListBean> projectList;//项目经历
    private List<CommonSocialBean> socialList;//社交经历

    private String token = "";
    private ResumePst resumePst;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        showStatusBar(R.id.layout_blue_head);
        tv_layout_blue_center.setText("在线预览");
        iv_layout_blue_share.setVisibility(View.VISIBLE);
        obs_scroll_view.smoothScrollTo(0, 0);
        obs_scroll_view.scrollTo(0, 0);
    }

    @Override
    protected int getLayoutResId() {
        return R.layout.aty_preview;
    }

    @Override
    protected void initialized() {
        resumePst = new ResumePst(this);
        token = application.getUserInfo().get("data");
        jobList = new ArrayList<>();
        socialList = new ArrayList<>();
        projectList = new ArrayList<>();
        educationList = new ArrayList<>();
    }

    @Override
    protected void requestData() {
        resumePst.resumeShow(token);

    }

    private void initJobHistoryAdapter() {
        previewJobHistoryAdapter = new PreviewJobHistoryAdapter(this, jobList);
        lv_preview_job_history.setAdapter(previewJobHistoryAdapter);
    }

    private void initEducationAdapter() {
        previewEducationAdapter = new PreviewEducationAdapter(this, educationList);
        lv_preview_education.setAdapter(previewEducationAdapter);
    }

    private void initProjectAdapter() {
        previewProjectAdapter = new PreviewProjectAdapter(this, projectList);
        lv_preview_project.setAdapter(previewProjectAdapter);
    }

    private void initSelfAdapter() {
        previewSelfAdapter = new PreviewSelfAdapter(this, socialList);
        lv_preview_self.setAdapter(previewSelfAdapter);
    }

    @Override
    public void onComplete(String requestUrl, String jsonStr) {
        super.onComplete(requestUrl, jsonStr);
        if (requestUrl.contains("resumeShow")) {
            //            L.e("==========resumeShow=========", jsonStr);
            PreviewBean previewBean = GsonUtil.GsonToBean(jsonStr, PreviewBean.class);
            Glide.with(this).load(previewBean.getData().getImg()).error(R.mipmap.icon_defult).placeholder(R.mipmap
                    .icon_defult).dontAnimate().into(iv_preview_head);
            tv_preview_name.setText(previewBean.getData().getName());
            if (TextUtils.isEmpty(previewBean.getData().getName()) && TextUtils.isEmpty(previewBean.getData().getSex
                    ())) {
                tv_preview_name.setVisibility(View.GONE);
            } else if (TextUtils.isEmpty(previewBean.getData().getName()) && !TextUtils.isEmpty(previewBean.getData()
                    .getSex())) {
                tv_preview_name.setVisibility(View.VISIBLE);
                tv_preview_name.setText(previewBean.getData().getSex());
            } else if (!TextUtils.isEmpty(previewBean.getData().getName()) && TextUtils.isEmpty(previewBean.getData()
                    .getSex())) {
                tv_preview_name.setVisibility(View.VISIBLE);
                tv_preview_name.setText(previewBean.getData().getName());
            } else {
                tv_preview_name.setVisibility(View.VISIBLE);
                tv_preview_name.setText(previewBean.getData().getName() + "-" + previewBean.getData().getSex());
            }
            if (TextUtils.isEmpty(previewBean.getData().getPosition())) {
                tv_preview_job.setVisibility(View.GONE);
            } else {
                tv_preview_job.setVisibility(View.VISIBLE);
                tv_preview_job.setText(previewBean.getData().getPosition());
            }
            if (TextUtils.isEmpty(previewBean.getData().getPhone())) {
                tv_preview_phone.setVisibility(View.GONE);
            } else {
                tv_preview_phone.setVisibility(View.VISIBLE);
                tv_preview_phone.setText(previewBean.getData().getPhone());
            }
            if (TextUtils.isEmpty(previewBean.getData().getWork())) {
                tv_preview_suffer.setVisibility(View.GONE);
            } else {
                tv_preview_suffer.setVisibility(View.VISIBLE);
                tv_preview_suffer.setText(previewBean.getData().getWork());
            }
            if (TextUtils.isEmpty(previewBean.getData().getEducation())) {
                tv_preview_education.setVisibility(View.GONE);
            } else {
                tv_preview_education.setVisibility(View.VISIBLE);
                tv_preview_education.setText(previewBean.getData().getEducation());
            }
            if (TextUtils.isEmpty(previewBean.getData().getPrice())) {
                tv_preview_pay.setVisibility(View.GONE);
                tv_preview_job_pay.setVisibility(View.GONE);
            } else {
                tv_preview_pay.setVisibility(View.VISIBLE);
                tv_preview_pay.setText(previewBean.getData().getPrice());
                tv_preview_job_pay.setVisibility(View.VISIBLE);
                tv_preview_job_pay.setText(previewBean.getData().getPrice());
            }
            if (TextUtils.isEmpty(previewBean.getData().getAddress())) {
                ll_preview_city.setVisibility(View.GONE);
            } else {
                ll_preview_city.setVisibility(View.VISIBLE);
                tv_preview_city.setText(previewBean.getData().getAddress());
            }
            if (TextUtils.isEmpty(previewBean.getData().getBirth())) {
                ll_preview_birthday.setVisibility(View.GONE);
            } else {
                ll_preview_birthday.setVisibility(View.VISIBLE);
                tv_preview_birthday.setText(previewBean.getData().getBirth());
            }
            if (TextUtils.isEmpty(previewBean.getData().getService())) {
                tv_preview_salary.setVisibility(View.GONE);
            } else {
                tv_preview_salary.setVisibility(View.VISIBLE);
                tv_preview_salary.setText(previewBean.getData().getService());
            }
            if (TextUtils.isEmpty(previewBean.getData().getJob_position())) {
                tv_preview_job_name.setVisibility(View.GONE);
            } else {
                tv_preview_job_name.setVisibility(View.VISIBLE);
                tv_preview_job_name.setText(previewBean.getData().getJob_position());
            }
            //            if(TextUtils.isEmpty(previewBean.getData().get))
            if (TextUtils.isEmpty(previewBean.getData().getJob_address())) {
                ll_preview_job_address.setVisibility(View.GONE);
            } else {
                ll_preview_job_address.setVisibility(View.VISIBLE);
                tv_preview_job_city.setText(previewBean.getData().getJob_address());
            }
            if (TextUtils.isEmpty(previewBean.getData().getTrade())) {
                ll_preview_job_trade.setVisibility(View.GONE);
            } else {
                ll_preview_job_trade.setVisibility(View.VISIBLE);
                tv_preview_job_trade.setText(previewBean.getData().getTrade());
            }
            jobList = previewBean.getData().getPractice_list();
            socialList = previewBean.getData().getSocial();
            projectList = previewBean.getData().getJob_list();
            educationList = previewBean.getData().getEducation_list();
            if (jobList.size() == 0) {
            } else {
                initJobHistoryAdapter();
            }
            if (educationList.size() == 0) {
            } else {
                initEducationAdapter();
            }
            if (projectList.size() == 0) {
            } else {
                initProjectAdapter();
            }
            if (socialList.size() == 0) {
            } else {
                initSelfAdapter();
            }
            if (TextUtils.isEmpty(previewBean.getData().getSelf_speak())) {
                tv_preview_appraise.setVisibility(View.GONE);
            } else {
                tv_preview_appraise.setVisibility(View.VISIBLE);
                tv_preview_appraise.setText(previewBean.getData().getSelf_speak());
            }
            return;
        }
    }
}
